package jdbc06;

import org.apache.commons.dbcp2.BasicDataSource;
import org.junit.Test;

import java.sql.Connection;
import java.sql.SQLException;

public class DBCPDemo {
@Test
    public void test() throws Exception {
//1.使用 BasicDataSource 基础数据源
    BasicDataSource bs = new BasicDataSource();
    //2.设置数据库连接参数
    bs.setDriverClassName("com.mysql.jdbc.Driver");

    bs.setUrl("jdbc:mysql://127.0.0.1/test?useSSL=false&characterEncoding=UTF-8");
            bs.setUsername("root");
    bs.setPassword("123456");
    //3.从数据源中获取一个连接
    Connection con = bs.getConnection();
    System.out.println(con);
}
}
